#include <bits/stdc++.h>

using namespace std;

const int N = 110;
int f[N][N][2];
class Solution
{


public:
    int countSubstrings(string s, string t)
    {
        memset(f, 0, sizeof(f));
        for (int i = 1; i <= s.size(); ++i)
        {
            for (int j = 1; j <= t.size(); ++j)
            {
                if (s[i - 1] == t[j - 1])
                {
                    f[i][j][1] = f[i - 1][j - 1][1];
                    f[i][j][1] = f[i - 1][j - 1][0] + 1;
                }
                else
                {
                    f[i][j][1] = f[i - 1][j - 1][0] + 1;
                }
            }
        }
        int ret = 0;
        for (int i = 1; i <= s.size(); ++i)
        {
            for (int j = 1; j <= t.size(); ++j)
            {
                ret += f[i][j][1];
            }
        }
        return ret;
    }
};